﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.Controls
{
    public partial class RepairRequestCtrl : BaseControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            gridRequests.GridBorder = BorderStyle.None;
            if (!IsPostBack)
            {
                lblCompany.Text = Branches.CurrentBranch.s_Name;
                lblAddress.Text = Branches.CurrentBranch.s_Address;
                lblABN.Text = Branches.CurrentBranch.s_ABN;
                lblFax.Text = Branches.CurrentBranch.s_Fax;
                lblPhone.Text = Branches.CurrentBranch.s_Phone;
                litFooter.Text = SysVars.RepairFooter;

                RefreshContent();
            }
        }

        const string BOOKING_JOB = "BOOKING_JOB";
        RepairJob bookedJobs
        {
            get { return (RepairJob)Session[BOOKING_JOB]; }
            set { Session.Remove(BOOKING_JOB); Session[BOOKING_JOB] = value; }
        }

        const string BOOKING_JOB_PROBLEMS = "BOOKING_JOB_PROBLEMS";
        RepairJobProblems bookedJobProblems
        {
            get { return (RepairJobProblems)Session[BOOKING_JOB_PROBLEMS]; }
            set { Session.Remove(BOOKING_JOB_PROBLEMS); Session[BOOKING_JOB_PROBLEMS] = value; }
        }

        public void RefreshContent()
        {
            lblCustomerName.Text = bookedJobs.s_CustomerName;
            lblCustomerPhone.Text = bookedJobs.s_CustomerPhone;

            lblCreatedDate.Text = bookedJobs.CreatedDate.ToString(SysVars.DateFormat);
            lblUserName.Text = SessionUser.s_FullName;

            gridRequests.SourceObject = bookedJobs;
            gridRequests.JobProblems = bookedJobProblems;
            gridRequests.Refresh();

            decimal total = 0;
            for (int i = 0; i < bookedJobProblems.RowCount; i++)
            {
                total += bookedJobProblems.Price;
                bookedJobProblems.MoveNext();
            }
            lblTotalAmount.Text = string.Format("{0:C}", total);
        }
    }
}